package com.copa.l342;

/**
 * @author copa
 * @createDate 2022-07-04 22:15
 * @function 二分查找法
 */
public class Test1 {

    public boolean isPowerOfFour(int n) {
        if (n < 1) {
            return false;
        }
        int left = 0;
        int right = n;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (Math.pow(4, mid) > n) {
                right = mid - 1;
                continue;
            }
            if (Math.pow(4, mid) < n) {
                left = mid + 1;
                continue;
            }
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new Test1().isPowerOfFour(2));
    }
}
